package com.xingdian.xingdianhulianserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.xingdian.xingdianhulianserver.common.QueryObject;
import com.xingdian.xingdianhulianserver.common.ServerResponse;
import com.xingdian.xingdianhulianserver.mapper.IpInfoMapper;
import com.xingdian.xingdianhulianserver.mapper.UserMapper;
import com.xingdian.xingdianhulianserver.service.IpInfoService;
import com.xingdian.xingdianhulianserver.vo.IpInfo;
import com.xingdian.xingdianhulianserver.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* *
 * @Author H2SO4
 * @ClassName: IpInfoService
 * @Description TODO
 * @Date 2019/11/26--15:18
 * */
@Service
public class IpInfoServiceImpl implements IpInfoService {

    @Autowired
    IpInfoMapper ipInfoMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public int add(IpInfo ipInfo){
        return ipInfoMapper.insertSelective(ipInfo);
    }

    //查询授权信息
    @Override
    public ServerResponse findinfo(QueryObject queryObject) {
        int total = ipInfoMapper.countInfo(queryObject);
        PageHelper.startPage((queryObject.getCurrentPage()/queryObject.getPageSize()+1),queryObject.getPageSize());
        List<IpInfo> ipInfos = ipInfoMapper.findinfo(queryObject);
        Map<String,Object> map = new HashMap<>();
        map.put("ipInfos",ipInfos);
        map.put("total",total);
        return ServerResponse.createBySuccess(map);
    }

    @Override
    public IpInfo findById(Integer id) {
        return ipInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateIpInfo(IpInfo ipInfo) {
        ipInfoMapper.updateByPrimaryKeySelective(ipInfo);
    }

    @Override
    public void delInfo(Integer id) {
        ipInfoMapper.delInfo(id);
    }

    @Override
    public User login(String userName, String password) {
        return userMapper.login(userName,password);
    }

    ;


}
